/**
* 版权所有：版权所有(C) 2014
* 文件编号：
* 文件名称: XMService.java
* 系统编号：
* 系统名称：贝优特项目管理
* 模块编号： 
* 模块名称：项目管理模块
* 设计文件：
* 完成日期：2014-12-01 
* 作    者：lanjinsheng
* 内容摘要：
* 属性描述：
* 方法描述：该类有n个方法：
* 文件调用：单例加载。在Control类中调用
*/
package com.beaut.project.service;

import java.math.BigDecimal;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Calendar;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.UUID;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.beaut.project.dao.CRMMapper;
import com.beaut.project.dao.FinanceMapper;
import com.beaut.project.dao.GDMapper;
import com.beaut.project.dao.XMAssistMapper;
import com.beaut.project.dao.XMFinanceMapper;
import com.beaut.project.dao.XMMapper;
import com.beaut.project.util.StaticData;
import com.beaut.project.util.Utility;

@Transactional(rollbackFor = Exception.class)
@Service("xmFinanceMapper")
public class XMFinanceService {
	@Autowired
	private XMFinanceMapper xmFinanceMapper;
	@Autowired
	private FinanceMapper financeMapper;
	@Autowired
	private XMMapper xmMapper;
	@Autowired
	private GDMapper gdMapper;
	@Autowired
	private CRMMapper crmMapper;
	@Autowired
	XMAssistMapper xMAssistMapper;//项目辅助管理
	public  String employReimbursem(Map<String,Object> map){
//		Map<String,Object> mapEmploy = xmFinanceMapper.getEmloyeeReimbursemById(map);
//		BigDecimal remMoney = new BigDecimal(String.valueOf(mapEmploy.get("reimbursement")));//报账金额
//		//查询出此员工的未还借款单
//		List<Map<String,Object>> listLoan =  xmFinanceMapper.listEmployeeLoan(mapEmploy);
//		List<Map<String,Object>> listNewLoan = new ArrayList<Map<String,Object>>();
//		if(listLoan.size()>0&&null!=listLoan){
//			//查询出此分包的未还借款单
//			for(int i=0;i<listLoan.size();i++){
//				Map<String,Object> mapLoan = listLoan.get(i);
//				if(null!=mapLoan){
//					BigDecimal loanMoney = new BigDecimal(String.valueOf(mapLoan.get("pay_money")));//借款金额+加本金
//					BigDecimal already_money = new BigDecimal(String.valueOf(mapLoan.get("already_money")));//借款金额+加本金
//					BigDecimal yetMoney =remMoney.add(already_money);
//					if(yetMoney.compareTo(loanMoney)==-1){
//						mapLoan.put("yet", "0");
//						mapLoan.put("money",yetMoney);
//						listNewLoan.add(mapLoan);
//						break;
//					}else if(yetMoney.compareTo(loanMoney)==0){
//						mapLoan.put("money",yetMoney);
//						mapLoan.put("yet", "0");
//						listNewLoan.add(mapLoan);
//						break;
//					}else{
//						BigDecimal yetM= loanMoney.subtract(already_money);
//						mapLoan.put("money",loanMoney);
//
//						mapLoan.put("yet", "0");
//						remMoney=yetMoney.subtract(yetM);
//					}
//					listNewLoan.add(mapLoan);
//				}
//			}
//		}
//		xmFinanceMapper.updateEmployeeLoan(listNewLoan);
		return Utility.rtJson(Utility.RETURN_OK, "报账成功", null);
	}
	public String addXMInvoice(Map<String,Object> map){
    	String operation_date = new SimpleDateFormat(StaticData.OPERATION_DATE_FORMATTER).format(new Date());
    	map.put("create_time", operation_date);
    	map.put("id", UUID.randomUUID().toString());
    	map.put("status", 0);
    	String workers = String.valueOf(map.get("workers"));
    	if(!Utility.isNullorEmpty(workers)){
    		List<Map<String,Object>> list = new ArrayList<Map<String,Object>>();
    		if(!Utility.isNullorEmpty(workers)){
    			String[] workersArr=workers.split(";");
    			for(int i=0;i<workersArr.length;i++){
    				Map<String,String> workerMap= Utility.json2Map(workersArr[i]);
    				Map<String,Object> m= new HashMap<String,Object>();
    				m.put("xm_invoice_id", map.get("id"));
    				m.put("team_type", StaticData.WORKER_OUT_INVOICE);
    				m.put("fbf_id", workerMap.get("worker_id"));
    				m.put("fbf", workerMap.get("worker_company"));
    				m.put("out_invoice", workerMap.get("out_invoice"));
    				m.put("tax", 0);
    				m.put("remark", workerMap.get("remark"));
    				list.add(m);
    			}
    		}
    		xmFinanceMapper.addXMInvoiceDetail(list);
    	}
    	/**
    	//公司付款部分
    	Map<String,Object> m= new HashMap<String,Object>();
		m.put("xm_invoice_id", map.get("id"));
		m.put("team_type", StaticData.COMPANY_SELF_OUT_INVOICE);
		m.put("fbf_id",null);
		m.put("fbf", null);
		m.put("out_invoice", map.get("company_out_invoice"));
		m.put("tax", map.get("company_tax"));
		m.put("remark", map.get("remark"));
		list.add(m);
		**/
    	xmFinanceMapper.addXMInvoice(map);
    	
		return Utility.rtJson(Utility.RETURN_OK, "添加成功", null);
	}
	public String addXMEndInvoice(Map<String,Object> map){
		String operation_date = new SimpleDateFormat(StaticData.OPERATION_DATE_FORMATTER).format(new Date());
		map.put("create_time", operation_date);
		map.put("id", UUID.randomUUID().toString());
		map.put("status", 0);
		String workers = String.valueOf(map.get("workers"));
		if(!Utility.isNullorEmpty(workers)){
			List<Map<String,Object>> list = new ArrayList<Map<String,Object>>();
			if(!Utility.isNullorEmpty(workers)){
				String[] workersArr=workers.split(";");
				for(int i=0;i<workersArr.length;i++){
					Map<String,String> workerMap= Utility.json2Map(workersArr[i]);
					Map<String,Object> m= new HashMap<String,Object>();
					m.put("xm_invoice_id", map.get("id"));
					m.put("team_type", StaticData.WORKER_OUT_INVOICE);
					m.put("fbf_id", workerMap.get("worker_id"));
					m.put("fbf", workerMap.get("worker_company"));
					m.put("out_invoice", workerMap.get("out_invoice"));
					m.put("tax", 0);
					m.put("remark", workerMap.get("remark"));
					list.add(m);
				}
			}
			xmFinanceMapper.addXMInvoiceDetail(list);
		}
		xmFinanceMapper.addXMEndInvoice(map);
		return Utility.rtJson(Utility.RETURN_OK, "添加成功", null);
	}
	public String addXMReimLoan(Map<String,Object> map){
		map.put("id", UUID.randomUUID().toString());
		map.put("status", 0);
		xmFinanceMapper.addXMReimLoan(map);
		return Utility.rtJson(Utility.RETURN_OK, "添加成功", null);
	}
	public String updateXMReimLoan(Map<String,Object> map){
		xmFinanceMapper.updateXMReimLoan(map);
		return Utility.rtJson(Utility.RETURN_OK, "添加成功", null);
	}
	/**
	 * 更新开票信息
	 * @param map
	 * @return
	 */
	public String updateXMInvoice(Map<String,Object> map){
		//当flagType等于1的情况表示确认之后需要修改票号，其他信息不能修改
		if("1".equals(String.valueOf(map.get("flagType")))){
			xmFinanceMapper.updateXmInvoiceTicket(map);
			map.put("business_id",map.get("rec_id"));
			map.put("business_type",StaticData.XM_SP);
			List<String> atts = Arrays.asList(String.valueOf(map.get("attachmentId")).split(","));
		    //收票附件
			List<Map<String,Object>> attList = getAttList(map, atts);
			if(attList.size() > 0){
				xmMapper.addXMAttachment(attList);
			}  
			
		}else{
	    	String workers = String.valueOf(map.get("workers"));
	    	String operation_date = new SimpleDateFormat(StaticData.OPERATION_DATE_FORMATTER).format(new Date());
	    	map.put("create_time", operation_date);
	//    	map.put("status", 0);
	    	List<Map<String,Object>> list=new ArrayList<Map<String,Object>>();
	    	xmFinanceMapper.deleteInvoiceDetail(map);
	    	if(!Utility.isNullorEmpty(workers)){
	    		String[] workersArr=workers.split(";");
	    		for(int i=0;i<workersArr.length;i++){
	    			Map<String,String> workerMap= Utility.json2Map(workersArr[i]);
	    			Map<String,Object> m= new HashMap<String,Object>();
	    			m.put("xm_invoice_id", map.get("id"));
	    			m.put("team_type", StaticData.WORKER_OUT_INVOICE);
	    			m.put("fbf_id", workerMap.get("worker_id"));
	    			m.put("fbf", workerMap.get("worker_company"));
	    			m.put("out_invoice", workerMap.get("out_invoice"));
	    			m.put("tax", 0);
	    			m.put("remark", workerMap.get("remark"));
	    			list.add(m);
	    		}
	    		xmFinanceMapper.addXMInvoiceDetail(list);
	    	}
	    	xmFinanceMapper.updateXMInvoice(map);
    	}
    	/**
    	//公司付款部分
    	Map<String,Object> m= new HashMap<String,Object>();
		m.put("xm_invoice_id", map.get("id"));
		m.put("team_type", StaticData.COMPANY_SELF_OUT_INVOICE);
		m.put("fbf_id",null);
		m.put("fbf", null);
		m.put("out_invoice", map.get("company_out_invoice"));
		m.put("tax", map.get("company_tax"));
		m.put("remark", map.get("remark"));
		list.add(m);
		**/
		return Utility.rtJson(Utility.RETURN_OK, "添加成功", null);
	}
	public String updateXMEndInvoice(Map<String,Object> map){
		String workers = String.valueOf(map.get("workers"));
		String operation_date = new SimpleDateFormat(StaticData.OPERATION_DATE_FORMATTER).format(new Date());
		map.put("create_time", operation_date);
		map.put("status", 0);
		List<Map<String,Object>> list=new ArrayList<Map<String,Object>>();
		xmFinanceMapper.deleteInvoiceDetail(map);
		if(!Utility.isNullorEmpty(workers)){
			String[] workersArr=workers.split(";");
			for(int i=0;i<workersArr.length;i++){
				Map<String,String> workerMap= Utility.json2Map(workersArr[i]);
				Map<String,Object> m= new HashMap<String,Object>();
				m.put("xm_invoice_id", map.get("id"));
				m.put("team_type", StaticData.WORKER_OUT_INVOICE);
				m.put("fbf_id", workerMap.get("worker_id"));
				m.put("fbf", workerMap.get("worker_company"));
				m.put("out_invoice", workerMap.get("out_invoice"));
				m.put("tax", 0);
				m.put("remark", workerMap.get("remark"));
				list.add(m);
			}
			xmFinanceMapper.addXMInvoiceDetail(list);
		}
		xmFinanceMapper.updateXMEndInvoice(map);
		return Utility.rtJson(Utility.RETURN_OK, "添加成功", null);
	}
	public String updateXmRecFlag(Map<String,Object> map){
		map.put("flag", "1");
		xmFinanceMapper.updateXmRecFlag(map);
		if("1".equals(String.valueOf(map.get("rec_type")))){
			map.put("work_in_invoice", map.get("rec_value"));
			xMAssistMapper.addXMWorkInInvoice(map);
		}else{
			map.put("purchase_in_invoice", map.get("rec_value"));
			xMAssistMapper.addXMPurchaseInVoice(map);
		}
		return Utility.rtJson(Utility.RETURN_OK, "添加成功", null);
	}
	public String listPageXMInvoice(Map<String,Object> map){
		List<Map<String,Object>> list= xmFinanceMapper.listPageXMInvoice(map);
		StringBuffer sb = new StringBuffer("");
		sb.append(Utility.lstMaptoJson(list));
		Utility.putSuccess(map);
		return sb.toString();
	}
	public String listFinanceInfoByYear(Map<String,Object> map){
		List<Map<String,Object>> list= xmFinanceMapper.listFinanceInfoByYear(map);
		StringBuffer sb = new StringBuffer("");
		sb.append(Utility.lstMaptoJson(list));
		Utility.putSuccess(map);
		return sb.toString();
	}
	public String listPageXMRecInvoice(Map<String,Object> map){
		List<Map<String,Object>> list= xmFinanceMapper.listPageXMRecInvoice(map);
		StringBuffer sb = new StringBuffer("");
		sb.append(Utility.lstMaptoJson(list));
		Utility.putSuccess(map);
		return sb.toString();
	}
	public String listPageXMRpLoan(Map<String,Object> map){
		List<Map<String,Object>> list= xmFinanceMapper.listPageXMRpLoan(map);
		StringBuffer sb = new StringBuffer("");
		sb.append(Utility.lstMaptoJson(list));
		Utility.putSuccess(map);
		return sb.toString();
	}
	public String listFbAdvances(Map<String,Object> map){
		List<Map<String,Object>> list= xmFinanceMapper.listFbAdvances(map);
		StringBuffer sb = new StringBuffer("");
		sb.append(Utility.lstMaptoJson(list));
		Utility.putSuccess(map);
		return sb.toString();
	}
	public String listPageXMReimbursement(Map<String,Object> map){
		List<Map<String,Object>> list= xmFinanceMapper.listPageXMReimbursement(map);
		StringBuffer sb = new StringBuffer("");
		sb.append(Utility.lstMaptoJson(list));
		Utility.putSuccess(map);
		return sb.toString();
	}
	
	public String getXMInvoiceById(Map<String,Object> map){
		Map<String,Object> xmInvoiceMap= xmFinanceMapper.getXMInvoiceById(map);
//		Map<String,Object> xmCompanyInvoiceMap= xmFinanceMapper.getXMCompanyInvoiceById(map);
//		xmInvoiceMap.put("company_out_invoice", xmCompanyInvoiceMap.get("out_invoice"));
//		xmInvoiceMap.put("company_tax", xmCompanyInvoiceMap.get("tax"));
		//附件
		xmInvoiceMap.put("business_id", map.get("id"));
		xmInvoiceMap.put("business_type",StaticData.XM_SP);
		List<Map<String,String>> attList = xmMapper.getXMTempAttachmentByGDId(xmInvoiceMap);
		StringBuilder attachmentId = new StringBuilder("");
		StringBuilder attachmentName = new StringBuilder("");
		if(attList != null && attList.size() > 0){
			for(int i=0;i<attList.size();i++){
				Map<String,String> m = attList.get(i);
				if(m != null){
					if(i==0){
						attachmentId.append(m.get("attachmentId"));
						attachmentName.append(m.get("attachmentName"));
					}else{
						attachmentId.append(",").append(m.get("attachmentId"));
						attachmentName.append("*").append(m.get("attachmentName"));
					}
				}
			}
		}
		xmInvoiceMap.put("attachmentId", attachmentId.toString());
		xmInvoiceMap.put("attachmentName", attachmentName.toString());
		
		return Utility.toJson(xmInvoiceMap);
	}
	public String getReimLoanById(Map<String,Object> map){
		Map<String,Object> reimLoanMap= xmFinanceMapper.getReimLoanById(map);
		return Utility.toJson(reimLoanMap);
	}
	public String getGdAdvancesMoneyById(Map<String,Object> map){
		Map<String,Object> adMap= xmFinanceMapper.getGdAdvancesMoneyById(map);
		return Utility.toJson(adMap);
	}
	public String getXMInvoiceDetail(Map<String,Object> map){
		List<Map<String,Object>> xmWorkersInvoiceList= xmFinanceMapper.getXMWorkersInvoiceById(map);

		return Utility.lstMaptoJson(xmWorkersInvoiceList);
	}
	public String deleteInvoice(Map<String,Object> map){
		xmFinanceMapper.deleteInvoice(map);
		xmFinanceMapper.deleteInvoiceDetail(map);
	   return Utility.rtJson(Utility.RETURN_OK, "删除成功", null);
	}
	public String deleteReimLoan(Map<String,Object> map){
		xmFinanceMapper.deleteReimLoan(map);
		return Utility.rtJson(Utility.RETURN_OK, "删除成功", null);
	}
	public String flowBackToXMBasesDeal(Map<String,Object> map){
		Map<String,Object> xmInvoiceMap= xmFinanceMapper.getXMInvoiceById(map);
		String invoice_type = String.valueOf(xmInvoiceMap.get("invoice_type"));
		String xm_id = xmInvoiceMap.get("xm_id").toString();
		if("1".equals(invoice_type)){
			//如果当前是结算开票，则更新当前项目的进度状态为“开票”(xm_progress_status=6)。
			Map<String,Object> queryMap = new HashMap<String,Object>();
			queryMap.put("xm_id", xm_id);
			queryMap.put("xm_progress_status", StaticData.INVOICE);
			xMAssistMapper.updateXMProgressStatus(queryMap);
		}
		//xm_Base 应收款增加
		Map<String,Object> m = new HashMap<String,Object>();
		m.put("id", xm_id);
		m.put("flag", "1");
		m.put("account_receivable",xmInvoiceMap.get("account_receivable"));
		xMAssistMapper.addXMAccountReceivable(m);

		//xm_base 在字段work_in_invoice 增加数量。
		Object worker_invoice = xmFinanceMapper.getWorkerInvoiceById(xmInvoiceMap);
		BigDecimal work_in_invoice = new BigDecimal(String.valueOf(worker_invoice));
		xmInvoiceMap.put("work_in_invoice", work_in_invoice);
		//xm_base 字段out_invoice 已开票增加
		BigDecimal d1 = new BigDecimal(String.valueOf(xmInvoiceMap.get("account_receivable")));
		xmInvoiceMap.put("out_invoice", d1);
		xmFinanceMapper.addXMOutAndWorkInInvoice(xmInvoiceMap);
		//增加施工队收票记录，表xm_rec_invoice操作
		List<Map<String, Object>> workers = xmFinanceMapper.getXMWorkersInvoiceById(xmInvoiceMap);
		BigDecimal workTax = new BigDecimal(0);
		String operation_date = new SimpleDateFormat(StaticData.OPERATION_DATE_FORMATTER).format(new Date());
		if(workers != null && workers.size() > 0){
			for(int i=0;i<workers.size();i++){
				Map<String,Object> worker = workers.get(i);
				//workTax = workTax.add(new BigDecimal(String.valueOf(worker.get("tax"))));
				Map<String,Object> m2 = new HashMap<String,Object>();
				m2.put("id", UUID.randomUUID().toString());
				m2.put("xm_id", xmInvoiceMap.get("xm_id"));
				m2.put("xm_name", xmInvoiceMap.get("xm_name"));
				m2.put("xm_code",xmInvoiceMap.get("xm_code"));
				m2.put("rec_type","1");
				m2.put("source","1");
				m2.put("invoice_id",map.get("key"));
				m2.put("rec_to_id", worker.get("worker_id"));
				m2.put("rec_to_name", worker.get("worker_company"));
				m2.put("operation_time", operation_date);
				m2.put("creator_id", xmInvoiceMap.get("creator_id"));
				m2.put("creator", xmInvoiceMap.get("creator"));
				m2.put("rec_value", worker.get("out_invoice"));
				m2.put("remark", "项目开票产生的分摊数据");
				m2.put("status", StaticData.PASS);
				xmFinanceMapper.addXMRecInvoice(m2);
			}
		}
		//开票税金管理
		xmInvoiceMap.put("company_tax", xmInvoiceMap.get("company_tax"));
		xmInvoiceMap.put("work_tax", workTax);
		xMAssistMapper.addXMTaxPrice(xmInvoiceMap);
		//项目的对应客户应收增加，ps:这里要说明的是：开票和客户应收是对应的，但是收票和分包商应付无直接关系。
		Map<String,Object> queryMap = new HashMap<String,Object>();
		queryMap.put("xm_id", xm_id);
		Map<String,Object> xmMap = xmMapper.getXMById(queryMap);
		String customer_id = String.valueOf(xmMap.get("customer_id"));
		queryMap.put("customer_id", customer_id);
		Map<String,Object> cfid = crmMapper.getCustomerFID(queryMap);
		String fid_id = UUID.randomUUID().toString();
		BigDecimal before_finance_in = new BigDecimal(0);
		if(cfid == null){
			cfid = new HashMap<String,Object>();
			cfid.put("id", fid_id);
			cfid.put("customer_id", customer_id);
			cfid.put("xm_id", xm_id);
			cfid.put("finance_in", d1);
			crmMapper.addCustomerFID(cfid);
			
		}else{
			before_finance_in = new BigDecimal(String.valueOf(cfid.get("finance_in")));
			cfid.put("finance_in", d1);
			crmMapper.updateCustomerFID(cfid);
			fid_id = String.valueOf(cfid.get("id"));
		}
		crmMapper.updateCustomerFI(cfid);
		Map<String,Object> fidLogMap = new HashMap<String,Object>();
		fidLogMap.put("detail_id", fid_id);
		fidLogMap.put("before_finance_in", before_finance_in);
		fidLogMap.put("customer_id", customer_id);
		fidLogMap.put("customer", xmMap.get("customer"));
		fidLogMap.put("operation_date", operation_date);
		fidLogMap.put("proof_type", StaticData.XM_INVOICE_OUT);
		fidLogMap.put("proof_id", map.get("id"));
		fidLogMap.put("finance_in", d1);
		fidLogMap.put("after_finance_in", before_finance_in.add(d1));
		fidLogMap.put("summary", "项目【"+String.valueOf(xmMap.get("xm_code"))+"】开票，应收增加");
		crmMapper.addCustomerFIDLog(fidLogMap);
		xmFinanceMapper.updateXmRecFlag(m);
		return "1";
	}	
	
	public String flowBackToXMInMoneyDeal(Map<String,Object> map){
		Map<String,Object> xmInMoneyMap= xmFinanceMapper.getInMoneyById(map);
		int in_type = Integer.parseInt(String.valueOf(xmInMoneyMap.get("in_type")));
		
		//更新发票的已收款update xm_invoice set has_receivable=has_receivable+#{in_money} where id=#{xm_invoice_id}
		xmFinanceMapper.addXMInvoiceHashReceivable(xmInMoneyMap);
		
		if(StaticData.INMONEY_ZB == in_type){
			//如果是质保金收款，还要更新质保金的已收额
			xmFinanceMapper.updateXMInvoiceWarranty(xmInMoneyMap);
		}
		
		//xm_base 增加has_receivable 数值。项目已收款，update xm_base set has_receivable=has_receivable+#{in_money} where id=#{xm_id}
		xMAssistMapper.addXMHasReceivable(xmInMoneyMap);
		
		//xm_base 增加manage_charge 数值。项目管理费，update xm_base set xm_manage_price=xm_manage_price+#{xm_manage_price} where id=#{xm_id}
		   Map<String,Object> m2 = new HashMap<String,Object>();
		   m2.put("xm_id", xmInMoneyMap.get("xm_id"));
		   m2.put("xm_manage_price", xmInMoneyMap.get("manage_money"));
		   xMAssistMapper.addXMManagePrice(m2);	
		   
			//项目辅助状态处理为进度收款
			Map<String,Object> mstatus=new HashMap<String, Object>();
			mstatus.put("xm_id", m2.get("xm_id"));
			if(StaticData.INMONEY_JD == in_type){
				mstatus.put("xm_business_step", StaticData.XM_HAS_JDSK);
			}else if(StaticData.INMONEY_JS == in_type){
				mstatus.put("xm_business_step", StaticData.XM_HAS_JSSR);
				//判断结算收款是否完成，完成则更新xm_base的xm_inmoney_balance_status为3，表示收款完成
				Map<String,Object> queryMap = new HashMap<String,Object>();
				queryMap.put("invoice_id", xmInMoneyMap.get("invoice_id"));
				xMAssistMapper.updateInMoneyBalanceStatus(queryMap);
			}else if(StaticData.INMONEY_ZB == in_type){
				mstatus.put("xm_business_step", StaticData.XM_HAS_ZBJ);
			}
			xMAssistMapper.addXMBusinessStep(mstatus);
			
			//该项目对应客户的应收减少
			Map<String,Object> queryMap = new HashMap<String,Object>();
			queryMap.put("customer_id", xmInMoneyMap.get("customer_id"));
			queryMap.put("xm_id", xmInMoneyMap.get("xm_id"));
			BigDecimal zero = new BigDecimal(0);
			BigDecimal in_money = new BigDecimal(String.valueOf(xmInMoneyMap.get("in_money")));
			zero = zero.subtract(in_money);
			queryMap.put("finance_in", zero);
			crmMapper.updateCustomerFI(queryMap);//客户应收总额减少
			
			Map<String,Object> cfid = crmMapper.getCustomerFID(queryMap);
			BigDecimal before_finance_in = new BigDecimal(String.valueOf(cfid.get("finance_in")));
			cfid.put("finance_in", zero);
			crmMapper.updateCustomerFID(cfid);//客户对应项目的应收减少
			
			//产生日志
			Map<String,Object> fidLogMap = new HashMap<String,Object>();
			fidLogMap.put("detail_id", cfid.get("id"));
			fidLogMap.put("before_finance_in", before_finance_in);
			fidLogMap.put("customer_id", xmInMoneyMap.get("customer_id"));
			fidLogMap.put("customer", xmInMoneyMap.get("customer"));
			fidLogMap.put("operation_date", new SimpleDateFormat(StaticData.OPERATION_DATE_FORMATTER).format(new Date()));
			fidLogMap.put("proof_type", StaticData.XM_FINANCE_IN);
			fidLogMap.put("proof_id", xmInMoneyMap.get("id"));
			fidLogMap.put("finance_in", in_money);
			fidLogMap.put("after_finance_in", before_finance_in.subtract(in_money));
			if(StaticData.INMONEY_JD == in_type){
				fidLogMap.put("summary", "项目【"+xmInMoneyMap.get("xm_code")+"】进度收款【"+in_money+"】，应收减少");
			}else if(StaticData.INMONEY_JS == in_type){
				fidLogMap.put("summary", "项目【"+xmInMoneyMap.get("xm_code")+"】结算收款【"+in_money+"】，应收减少");
			}else if(StaticData.INMONEY_ZB == in_type){
				fidLogMap.put("summary", "项目【"+xmInMoneyMap.get("xm_code")+"】质保金收款【"+in_money+"】，应收减少");
			}
			crmMapper.addCustomerFIDLog(fidLogMap);
			
		return null;
	}		
	public String listPageXMInMoney(Map<String,Object> map){
		List<Map<String,Object>> list= xmFinanceMapper.listPageXMInMoney(map);
		StringBuffer sb = new StringBuffer("");
		sb.append(Utility.lstMaptoJson(list));
		Utility.putSuccess(map);
		return sb.toString();
	}
	public String addXMInMoney(Map<String,Object> map){	
		String operation_time = new SimpleDateFormat(StaticData.OPERATION_DATE_FORMATTER).format(new Date());
    	map.put("operation_time", operation_time);
    	map.put("id", UUID.randomUUID().toString());
    	map.put("status", 0);
    	map.put("in_type", StaticData.INMONEY_JD);
	   	xmFinanceMapper.addXMInMoney(map);
		return Utility.rtJson(Utility.RETURN_OK, "添加成功", null);	
	}
	public String addXMEndInMoney(Map<String,Object> map){	
		String operation_time = new SimpleDateFormat(StaticData.OPERATION_DATE_FORMATTER).format(new Date());
		map.put("operation_time", operation_time);
		map.put("id", UUID.randomUUID().toString());
		map.put("status", 0);
		map.put("in_type", StaticData.INMONEY_JS);
		xmFinanceMapper.addXMInMoney(map);
		return Utility.rtJson(Utility.RETURN_OK, "添加成功", null);	
	}
	public String addXMWarrantyInMoney(Map<String,Object> map){	
		String operation_time = new SimpleDateFormat(StaticData.OPERATION_DATE_FORMATTER).format(new Date());
		map.put("operation_time", operation_time);
		map.put("id", UUID.randomUUID().toString());
		map.put("status", 0);
		map.put("in_type", StaticData.INMONEY_ZB);
		xmFinanceMapper.addXMInMoney(map);
		return Utility.rtJson(Utility.RETURN_OK, "添加成功", null);	
	}
	
	public String updateXMEndInMoney(Map<String,Object> map){	
		String operation_time = new SimpleDateFormat(StaticData.OPERATION_DATE_FORMATTER).format(new Date());
		map.put("operation_time", operation_time);
		map.put("status", 0);
		xmFinanceMapper.updateXMInMoney(map);
		return Utility.rtJson(Utility.RETURN_OK, "添加成功", null);	
	}

    /**
     * 项目收款更新
     */
	public String updateXMInMoney(Map<String,Object> map){	
		String operation_time = new SimpleDateFormat(StaticData.OPERATION_DATE_FORMATTER).format(new Date());
    	map.put("operation_time", operation_time);
//    	map.put("id", UUID.randomUUID().toString());
    	map.put("status", 0);
	   	xmFinanceMapper.updateXMInMoney(map);
		return Utility.rtJson(Utility.RETURN_OK, "添加成功", null);	
	}
	public String getInMoneyById(Map<String,Object> map){
		Map<String,Object> inMoneyMap= xmFinanceMapper.getInMoneyById(map);

		return Utility.toJson(inMoneyMap);
	}
	public String deleteInMoney(Map<String,Object> map){
		xmFinanceMapper.deleteInMoney(map);
	   return Utility.rtJson(Utility.RETURN_OK, "删除成功", null);
	}
    /**
     * 项目支付管理
     */
	public String listPageXMPayment(Map<String,Object> map){
		List<Map<String,Object>> list= xmFinanceMapper.listPageXMPayment(map);
		StringBuffer sb = new StringBuffer("");
		sb.append(Utility.lstMaptoJson(list));
		Utility.putSuccess(map);
		return sb.toString();
	}
    /**
     * 项目结算支付管理
     */
	public String listPageXMEndPayment(Map<String,Object> map){
		List<Map<String,Object>> list= xmFinanceMapper.listPageXMEndPayment(map);
		StringBuffer sb = new StringBuffer("");
		sb.append(Utility.lstMaptoJson(list));
		Utility.putSuccess(map);
		return sb.toString();
	}
    /**
     * 项目支付选择供应商
     */
	public String listXMSuppliers(Map<String,Object> map){
		List<Map<String,Object>> list= xmFinanceMapper.listXMSuppliers(map);
		StringBuffer sb = new StringBuffer("");
		sb.append(Utility.lstMaptoJson(list));
		Utility.putSuccess(map);
		return sb.toString();
	}
    /**
     * 项目支付选择施工队
     */
	public String listXMWorkers(Map<String,Object> map){
		List<Map<String,Object>> list= xmFinanceMapper.listXMWorkers(map);
		for(int i=0;i<list.size();i++){
			Map<String,Object> mapWork = list.get(i);
			//查询分包借款金额
			Map<String,Object> mapLoanMoney = xmFinanceMapper.getWorkLoanMoneyById(mapWork);
			mapWork.put("loan_money", mapLoanMoney.get("loan_money"));
		}
		StringBuffer sb = new StringBuffer("");
		sb.append(Utility.lstMaptoJson(list));
		Utility.putSuccess(map);
		return sb.toString();
	}
	
	
    /**
     * 项目工单供应商支付
     */
	public String listXMGDSupplyPayment(Map<String,Object> map){
		List<Map<String,Object>> list= xmFinanceMapper.listXMGDSupplyPayment(map);
		StringBuffer sb = new StringBuffer("");
		sb.append(Utility.lstMaptoJson(list));
		Utility.putSuccess(map);
		return sb.toString();
	}
    /**
     * 项目工单施工方支付
     */
	public String listXMGDWorkerPayment(Map<String,Object> map){
		List<Map<String,Object>> list= new ArrayList<Map<String,Object>>();
		if(!Utility.isNullorEmpty(String.valueOf(map.get("xm_id")))){
			list = xmFinanceMapper.listXMGDWorkerPayment(map);
		}
		StringBuffer sb = new StringBuffer("");
		sb.append(Utility.lstMaptoJson(list));
		Utility.putSuccess(map);
		return sb.toString();
	}
    /**
     * 项目工单供应商支付
     */
	public String addXMPaySupply(Map<String,Object> map){
    	String gds = String.valueOf(map.get("gds"));
    	String operation_time = new SimpleDateFormat(StaticData.OPERATION_DATE_FORMATTER).format(new Date());
    	map.put("operation_time", operation_time);
    	map.put("id", UUID.randomUUID().toString());
    	map.put("status", 0);
    	map.put("cut_payment", 0);
    	map.put("pay_type", 2);
    	map.put("in_type",StaticData.PAY_JD);
    	String[] gdsArr=gds.split(";");
    	List<Map<String,Object>> list=new ArrayList<Map<String,Object>>();
    	BigDecimal 	before_finance_out = new BigDecimal(0);	
    	for(int i=0;i<gdsArr.length;i++){
    		Map<String,String> gdMap= Utility.json2Map(gdsArr[i]);
    		Map<String,Object> m= new HashMap<String,Object>();
    		m.put("xm_pay_id", map.get("id"));
    		m.put("pay_value", gdMap.get("now_pay"));
    		m.put("gd_id", gdMap.get("gd_id"));
    		m.put("remark", gdMap.get("remark"));
    		m.put("bus_id", gdMap.get("bus_id"));
    		m.put("cut_payment", 0);
    		before_finance_out = before_finance_out.add(new BigDecimal(String.valueOf(gdMap.get("finance_out"))));
    		list.add(m);
    	}
    	//付款申请部分
    	map.put("before_finance_out", before_finance_out);
    	xmFinanceMapper.addXMGDSupplyWorkerPayment(map);
    	xmFinanceMapper.addXMGDSupplyWorkerPaymentDetail(list);
    	xmFinanceMapper.updateSupplierFinanceOutDetailList(list);
		return Utility.rtJson(Utility.RETURN_OK, "添加成功", null);
	}
	
    /**
     * 项目工单供应商结算支付
     */
	public String addXMPayEndSupply(Map<String,Object> map){
    	String gds = String.valueOf(map.get("gds"));
    	String operation_time = new SimpleDateFormat(StaticData.OPERATION_DATE_FORMATTER).format(new Date());
    	map.put("operation_time", operation_time);
    	map.put("id", UUID.randomUUID().toString());
    	map.put("status", 0);
    	map.put("cut_payment", 0);
    	map.put("pay_type", 2);
    	map.put("in_type", StaticData.PAY_JS);
    	String[] gdsArr=gds.split(";");
    	List<Map<String,Object>> list=new ArrayList<Map<String,Object>>();
    	Double 	before_finance_out=0d;	
    	for(int i=0;i<gdsArr.length;i++){
    		Map<String,String> gdMap= Utility.json2Map(gdsArr[i]);
    		Map<String,Object> m= new HashMap<String,Object>();
    		m.put("xm_pay_id", map.get("id"));
    		m.put("pay_value", gdMap.get("now_pay"));
    		m.put("gd_id", gdMap.get("gd_id"));
    		m.put("remark", gdMap.get("remark"));
    		m.put("bus_id", gdMap.get("bus_id"));
    		m.put("cut_payment", 0);
//    		before_finance_out+=Double.parseDouble(gdMap.get("finance_out"));
    		list.add(m);
    	}
    	//付款申请部分
    	map.put("before_finance_out", before_finance_out);
    	xmFinanceMapper.addXMGDSupplyWorkerPayment(map);
    	xmFinanceMapper.addXMGDSupplyWorkerPaymentDetail(list);
		return Utility.rtJson(Utility.RETURN_OK, "添加成功", null);
	}
	
    /**
     * 项目工单施工方支付
     */
	public String addXMPayWorker(Map<String,Object> map){
    	String gds = String.valueOf(map.get("gds"));
    	String advs = String.valueOf(map.get("advs"));
    	String operation_time = new SimpleDateFormat(StaticData.OPERATION_DATE_FORMATTER).format(new Date());
    	map.put("operation_time", operation_time);
    	map.put("id", UUID.randomUUID().toString());
    	map.put("status", 0);
    	map.put("pay_type", 1);
      	map.put("in_type", 0);
      	String[] advsArr=advs.split(";");
    	List<Map<String,Object>> list=new ArrayList<Map<String,Object>>();
    	if(gds!=null&&!"".equals(gds)){
	    	String[] gdsArr=gds.split(";");
	    	for(int i=0;i<gdsArr.length;i++){
	    		Map<String,String> gdMap= Utility.json2Map(gdsArr[i]);
	    		Map<String,Object> m= new HashMap<String,Object>();
	    		m.put("xm_pay_id", map.get("id"));
	    		m.put("pay_value", gdMap.get("now_pay"));
	    		m.put("gd_id", gdMap.get("gd_id"));
	    		m.put("remark", gdMap.get("remark"));
	    		m.put("bus_id", gdMap.get("remark"));
	    		m.put("cut_payment", 0);
	    		list.add(m);
	    	}
	    	xmFinanceMapper.addXMGDSupplyWorkerPaymentDetail(list);
    	}
    	//添加扣垫款记录
    	List<Map<String,String>> listAdvs=new ArrayList<Map<String,String>>();
 
    	for(int i=0;i<advsArr.length;i++){
    		Map<String,String> advMap= Utility.json2Map(advsArr[i]);
    		Map<String,String> m= new HashMap<String,String>();
    		
    		m.put("voucher_id", String.valueOf(map.get("id")));
    		m.put("advances_id", advMap.get("id"));
    		m.put("money", advMap.get("yet_money"));
    		m.put("on_money", advMap.get("now_on_money"));
    		m.put("lxMoney", advMap.get("lxMoney"));
    		m.put("yet", "1");
    		m.put("advances_type", String.valueOf(StaticData.Proof_FB_Yet_Advances_IN));
    		listAdvs.add(m);
    	}
    	//付款申请部分
    	map.put("before_finance_out", 0);
    	BigDecimal cut_payment = new BigDecimal(String.valueOf(map.get("cut_payment")));
    	    	if(new BigDecimal(String.valueOf(map.get("pay_value"))).compareTo(new BigDecimal("0"))==1){
    		cut_payment=new BigDecimal(String.valueOf(map.get("loan_money")));
    	}else{
    		cut_payment=new BigDecimal(String.valueOf(map.get("payValue")));
    	}
    	map.put("cut_payment", cut_payment);
    	xmFinanceMapper.addXMGDSupplyWorkerPayment(map);
    	//项目进度支付还垫款
    	gdMapper.addGdYetTempAdvances(listAdvs);
		return Utility.rtJson(Utility.RETURN_OK, "添加成功", null);
	}
	
	 /**
     * 项目工单施工方支付-结算
     */
	public String addXMEndPayWorker(Map<String,Object> map){
    	String gds = String.valueOf(map.get("gds"));
    	String advs = String.valueOf(map.get("advs"));
    	String operation_time = new SimpleDateFormat(StaticData.OPERATION_DATE_FORMATTER).format(new Date());
    	map.put("operation_time", operation_time);
    	map.put("id", UUID.randomUUID().toString());
    	map.put("status", 0);
    	map.put("pay_type", 1);
      	map.put("in_type",1);
      	String[] gdsArr=null;
      	String[] advsArr = null;
      	if(!Utility.isNullorEmpty(advs)){
      		
      		advsArr = advs.split(";");
      	}
      	if(!Utility.isNullorEmpty(gds)){
      		
      		gdsArr = gds.split(";");
      	}
    	List<Map<String,Object>> list=new ArrayList<Map<String,Object>>();
    	Double 	before_finance_out=0d;	

    	//添加扣垫款记录
    	List<Map<String,String>> listAdvs=new ArrayList<Map<String,String>>();
       	Map<String,BigDecimal> gdAdvs=new HashMap<String, BigDecimal>();//统计工单垫款
       	if(advsArr != null && advsArr.length > 0){
       		for(int i=0;i<advsArr.length;i++){
       			Map<String,String> advMap= Utility.json2Map(advsArr[i]);
       			Map<String,String> m= new HashMap<String,String>();
       			//统计工单垫款
       			String gd_id=advMap.get("gd_id");
       			if(gdAdvs.get(gd_id)!=null && gdAdvs.get(gd_id).doubleValue()>0){
       				BigDecimal d=gdAdvs.get(gd_id).add(new BigDecimal(advMap.get("yet_money")));
       				gdAdvs.put(gd_id,d);
       			}else{
       				BigDecimal d=new BigDecimal(advMap.get("yet_money"));
       				gdAdvs.put(gd_id,d);
       			}
       			//统计工单垫款
       			m.put("voucher_id", String.valueOf(map.get("id")));
       			m.put("advances_id", advMap.get("id"));
       			m.put("money", advMap.get("yet_money"));
       			m.put("on_money", advMap.get("now_on_money"));
       			m.put("lxMoney", advMap.get("lxMoney"));
       			m.put("yet", "1");
       			m.put("advances_type", String.valueOf(StaticData.Proof_FB_Yet_Advances_IN));
       			listAdvs.add(m);
       		}
       		//项目进度支付还垫款
        	gdMapper.addGdYetTempAdvances(listAdvs);
       	}
    	if(gdsArr != null && gdsArr.length > 0){
    		for(int i=0;i<gdsArr.length;i++){
    			Map<String,String> gdMap= Utility.json2Map(gdsArr[i]);
    			Map<String,Object> m= new HashMap<String,Object>();
    			m.put("xm_pay_id", map.get("id"));
    			m.put("pay_value", gdMap.get("end_now_pay"));
    			m.put("gd_id", gdMap.get("gd_id"));
    			m.put("remark", gdMap.get("remark"));
    			m.put("bus_id", gdMap.get("bus_id"));
    			m.put("cut_payment", gdAdvs.get(gdMap.get("gd_id"))==null?0d:gdAdvs.get( gdMap.get("gd_id")));
//    		before_finance_out+=Double.parseDouble(gdMap.get("finance_out"));
    			list.add(m);
    		}
    		xmFinanceMapper.addXMGDSupplyWorkerPaymentDetail(list);
    	}
    	map.put("before_finance_out", before_finance_out);
    	BigDecimal cut_payment = new BigDecimal(String.valueOf(map.get("cut_payment")));
    	if(new BigDecimal(String.valueOf(map.get("pay_value"))).compareTo(new BigDecimal("0"))==1){
    		cut_payment=new BigDecimal(String.valueOf(map.get("loan_money")));
    	}else{
    		cut_payment=new BigDecimal(String.valueOf(map.get("payValue")));
    	}
    	map.put("cut_payment", cut_payment);
    	xmFinanceMapper.addXMGDSupplyWorkerPayment(map);
    	
    	
		return Utility.rtJson(Utility.RETURN_OK, "添加成功", null);
	}
	
	/**
     * 更新项目工单供应商支付
     */	
	public String updateXMPaySupply(Map<String,Object> map){
    	String gds = String.valueOf(map.get("gds"));
    	String operation_time = new SimpleDateFormat(StaticData.OPERATION_DATE_FORMATTER).format(new Date());
    	map.put("operation_time", operation_time);
    	map.put("status", 0);
    	map.put("cut_payment", 0);
    	map.put("pay_type", 2);
    	map.put("in_type", 0);
    	String[] gdsArr=gds.split(";");
    	List<Map<String,Object>> list=new ArrayList<Map<String,Object>>();
    	BigDecimal 	before_finance_out = new BigDecimal(0);	
    	for(int i=0;i<gdsArr.length;i++){
    		Map<String,String> gdMap= Utility.json2Map(gdsArr[i]);
    		Map<String,Object> m= new HashMap<String,Object>();
    		m.put("xm_pay_id", map.get("id"));
    		m.put("pay_value", gdMap.get("now_pay"));
    		m.put("gd_id", gdMap.get("gd_id"));
    		m.put("remark", gdMap.get("remark"));
    		m.put("bus_id", gdMap.get("bus_id"));
    		m.put("cut_payment", 0);
    		before_finance_out = before_finance_out.add(new BigDecimal(String.valueOf(gdMap.get("finance_out"))));
    		list.add(m);
    	}
    	//付款申请部分
    	map.put("before_finance_out", before_finance_out);
    	xmFinanceMapper.updateXMGDSupplyPayment(map);
    	xmFinanceMapper.deleteXMPaymentDetail(map);
    	xmFinanceMapper.addXMGDSupplyWorkerPaymentDetail(list);
		return Utility.rtJson(Utility.RETURN_OK, "添加成功", null);
	}
	/**
     * 更新项目工单供应商支付-结算
     */	
	public String updateXMEndPaySupply(Map<String,Object> map){
    	String gds = String.valueOf(map.get("gds"));
    	String operation_time = new SimpleDateFormat(StaticData.OPERATION_DATE_FORMATTER).format(new Date());
    	map.put("operation_time", operation_time);
    	map.put("status", 0);
    	map.put("cut_payment", 0);
    	map.put("pay_type", 2);
    	map.put("in_type", 1);
    	String[] gdsArr=gds.split(";");
    	List<Map<String,Object>> list=new ArrayList<Map<String,Object>>();
    	Double 	before_finance_out=0d;	
    	for(int i=0;i<gdsArr.length;i++){
    		Map<String,String> gdMap= Utility.json2Map(gdsArr[i]);
    		Map<String,Object> m= new HashMap<String,Object>();
    		m.put("xm_pay_id", map.get("id"));
    		m.put("pay_value", gdMap.get("now_pay"));
    		m.put("gd_id", gdMap.get("gd_id"));
    		m.put("remark", gdMap.get("remark"));
    		m.put("bus_id", gdMap.get("bus_id"));
    		m.put("cut_payment", 0);
//    		before_finance_out+=Double.parseDouble(gdMap.get("finance_out"));
    		list.add(m);
    	}
    	//付款申请部分
    	map.put("before_finance_out", before_finance_out);
    	xmFinanceMapper.updateXMGDSupplyPayment(map);
    	xmFinanceMapper.deleteXMPaymentDetail(map);
    	xmFinanceMapper.addXMGDSupplyWorkerPaymentDetail(list);
		return Utility.rtJson(Utility.RETURN_OK, "添加成功", null);
	}
	/**
     * 更新项目工单施工方支付
     */	
	public String updateXMPayWorker(Map<String,Object> map){
    	String gds = String.valueOf(map.get("gds"));
    	String advs = String.valueOf(map.get("advs"));
    	String operation_time = new SimpleDateFormat(StaticData.OPERATION_DATE_FORMATTER).format(new Date());
    	map.put("operation_time", operation_time);
    	map.put("status", 0);
    	map.put("pay_type", 1);
    	String[] gdsArr=gds.split(";");
    	String[] advsArr=advs.split(";");
    	List<Map<String,Object>> list=new ArrayList<Map<String,Object>>();
    	xmFinanceMapper.deleteXMPaymentDetail(map);
    	if(gds!=null&&!"".equals(gds)){
	    	for(int i=0;i<gdsArr.length;i++){
	    		Map<String,String> gdMap= Utility.json2Map(gdsArr[i]);
	    		Map<String,Object> m= new HashMap<String,Object>();
	    		m.put("xm_pay_id", map.get("id"));
	    		m.put("pay_value", gdMap.get("now_pay"));
	    		m.put("gd_id", gdMap.get("gd_id"));
	    		m.put("remark", gdMap.get("remark"));
	    		m.put("bus_id", gdMap.get("remark"));
	    		m.put("cut_payment", 0);
	    		list.add(m);
	    	}
	    	xmFinanceMapper.addXMGDSupplyWorkerPaymentDetail(list);
    	}
    	//添加扣垫款记录
    	gdMapper.deleteGdYetTempAdvances(map);
    	List<Map<String,String>> listAdvs=new ArrayList<Map<String,String>>();
    	for(int i=0;i<advsArr.length;i++){
    		Map<String,String> advMap= Utility.json2Map(advsArr[i]);
    		Map<String,String> m= new HashMap<String,String>();
    		m.put("voucher_id", String.valueOf(map.get("id")));
    		m.put("advances_id", advMap.get("id"));
    		m.put("money", advMap.get("yet_money"));
    		m.put("on_money", advMap.get("now_on_money"));
    		m.put("lxMoney", advMap.get("lxMoney"));
    		m.put("yet", "1");
    		m.put("advances_type", String.valueOf(StaticData.Proof_FB_Yet_Advances_IN));
    		listAdvs.add(m);
    	}
    	//付款申请部分
    	map.put("before_finance_out", 0);
    	BigDecimal cut_payment = new BigDecimal(String.valueOf(map.get("cut_payment")));
    	if(new BigDecimal(String.valueOf(map.get("pay_value"))).compareTo(new BigDecimal("0"))==1){
    		cut_payment=new BigDecimal(String.valueOf(map.get("loan_money")));
    	}else{
    		cut_payment=new BigDecimal(String.valueOf(map.get("payValue")));
    	}
    	map.put("cut_payment", cut_payment);
    	xmFinanceMapper.updateXMGDSupplyPayment(map);
    	//项目进度支付还垫款
    	gdMapper.addGdYetTempAdvances(listAdvs);
		return Utility.rtJson(Utility.RETURN_OK, "添加成功", null);
	}
	
	/**
     * 更新项目工单施工方支付
     */	
	public String updateXMEndPayWorker(Map<String,Object> map){
    	String gds = String.valueOf(map.get("gds"));
    	String advs = String.valueOf(map.get("advs"));
    	String operation_time = new SimpleDateFormat(StaticData.OPERATION_DATE_FORMATTER).format(new Date());
    	map.put("operation_time", operation_time);
    	map.put("status", 0);
    	map.put("pay_type", 1);
    	String[] gdsArr=null;
      	String[] advsArr = null;
      	if(!Utility.isNullorEmpty(advs)){
      		
      		advsArr = advs.split(";");
      	}
      	if(!Utility.isNullorEmpty(gds)){
      		
      		gdsArr = gds.split(";");
      	}
    	List<Map<String,Object>> list=new ArrayList<Map<String,Object>>();
    	Double 	before_finance_out=0d;	

    	//添加扣垫款记录
    	Map<String,BigDecimal> gdAdvs = new HashMap<String, BigDecimal>();//统计工单垫款
    	List<Map<String,String>> listAdvs = new ArrayList<Map<String,String>>();
    	if(advsArr != null && advsArr.length >0){
    		gdMapper.deleteGdYetTempAdvances(map);
    		for(int i=0;i<advsArr.length;i++){
    			Map<String,String> advMap= Utility.json2Map(advsArr[i]);
    			Map<String,String> m= new HashMap<String,String>();
    			//统计工单垫款
    			String gd_id=advMap.get("gd_id");
    			if(gdAdvs.get(gd_id)!=null && gdAdvs.get(gd_id).doubleValue()>0){
    				BigDecimal d=gdAdvs.get(gd_id).add(new BigDecimal(advMap.get("yet_money")));
    				gdAdvs.put(gd_id,d);
    			}else{
    				BigDecimal d=new BigDecimal(advMap.get("yet_money"));
    				gdAdvs.put(gd_id,d);
    			}
    			//统计工单垫款
    			m.put("voucher_id", String.valueOf(map.get("id")));
    			m.put("advances_id", advMap.get("id"));
    			m.put("money", advMap.get("yet_money"));
    			m.put("on_money", advMap.get("now_on_money"));
    			m.put("lxMoney", advMap.get("lxMoney"));
    			m.put("yet", "1");
    			m.put("advances_type", String.valueOf(StaticData.Proof_FB_Yet_Advances_IN));
    			listAdvs.add(m);
    		}
    		//项目进度支付还垫款
        	gdMapper.addGdYetTempAdvances(listAdvs);
    	}
    	if(gdsArr != null && gdsArr.length > 0){
    		xmFinanceMapper.deleteXMPaymentDetail(map);
    		for(int i=0;i<gdsArr.length;i++){
    			Map<String,String> gdMap= Utility.json2Map(gdsArr[i]);
    			Map<String,Object> m= new HashMap<String,Object>();
    			
    			m.put("xm_pay_id", map.get("id"));
    			m.put("pay_value", gdMap.get("end_now_pay"));
    			m.put("gd_id", gdMap.get("gd_id"));
    			m.put("remark", gdMap.get("remark"));
    			m.put("bus_id", gdMap.get("bus_id"));
    			m.put("cut_payment", 0);
//    		before_finance_out+=Double.parseDouble(gdMap.get("finance_out"));
    			list.add(m);
    		}
    		xmFinanceMapper.addXMGDSupplyWorkerPaymentDetail(list);
    	}
    	//付款申请部分
    	map.put("before_finance_out", before_finance_out);
    	BigDecimal cut_payment = new BigDecimal(String.valueOf(map.get("cut_payment")));
    	if(new BigDecimal(String.valueOf(map.get("pay_value"))).compareTo(new BigDecimal("0"))==1){
    		cut_payment=new BigDecimal(String.valueOf(map.get("loan_money")));
    	}else{
    		cut_payment=new BigDecimal(String.valueOf(map.get("payValue")));
    	}
    	map.put("cut_payment", cut_payment);
    	xmFinanceMapper.updateXMGDSupplyPayment(map);
    	
		return Utility.rtJson(Utility.RETURN_OK, "添加成功", null);
	}
    /**
     * 项目支付供应商申请查看
     */
	public String viewXmPay(Map<String,Object> map){
		Map<String,Object> inMoneyMap= xmFinanceMapper.viewXmPay(map);
		Map<String,Object> mapLoanParam = new HashMap<String,Object>();
		mapLoanParam.put("fb_advances_id", inMoneyMap.get("pay_to_id"));
		Map<String,Object> mapAlreadyMoney = crmMapper.getWorkerAdvancesMoney(mapLoanParam);
		inMoneyMap.put("loan_money",mapAlreadyMoney.get("already_money"));
		return Utility.toJson(inMoneyMap);
	}
	public String viewXmPayDetail(Map<String,Object> map){
		List<Map<String,Object>> list= xmFinanceMapper.viewXmPayDetail(map);
		StringBuffer sb = new StringBuffer("");
		sb.append(Utility.lstMaptoJson(list));
		Utility.putSuccess(map);
		return sb.toString();
	}
	/**
     * 查看项目工单施工方支付申请表详情
     */
	public String viewXmPayWorkerDetail(Map<String,Object> map){
		List<Map<String,Object>> list= xmFinanceMapper.viewXmPayWorkerDetail(map);
		StringBuffer sb = new StringBuffer("");
		sb.append(Utility.lstMaptoJson(list));
		Utility.putSuccess(map);
		return sb.toString();
	}
	//删除支付申请单
	public String deleteXMPayment(Map<String,Object> map){
		xmFinanceMapper.deleteXMPayment(map);
		xmFinanceMapper.deleteXMPaymentDetail(map);
		xmFinanceMapper.updateSupplierFinanceOutDetail(map);
		gdMapper.deleteGdYetTempAdvances(map);
	   return Utility.rtJson(Utility.RETURN_OK, "删除成功", null);
	}
	//财务未处理项目支付
	public String listPageXMFinancePayment(Map<String,Object> map){
		List<Map<String,Object>> list= xmFinanceMapper.listPageXMFinancePayment(map);
		StringBuffer sb = new StringBuffer("");
		sb.append(Utility.lstMaptoJson(list));
		Utility.putSuccess(map);
		return sb.toString();
	}
	//财务已处理项目支付
	public String listPageXMFinanceFinishPayment(Map<String,Object> map){
		List<Map<String,Object>> list= xmFinanceMapper.listPageXMFinanceFinishPayment(map);
		StringBuffer sb = new StringBuffer("");
		sb.append(Utility.lstMaptoJson(list));
		Utility.putSuccess(map);
		return sb.toString();
	}
	public String deleteReimbursement(Map<String,Object> map){
		Map<String,Object>mapRem=null;
		List<String> list = Arrays.asList(String.valueOf(map.get("ids")).split(","));
		for(int i=0;i<list.size();i++){
			mapRem=new HashMap<String,Object>();
			mapRem.put("id", list.get(i));
			xmFinanceMapper.deleteTempXmBz(mapRem);
			xmFinanceMapper.deleteReimbursement(mapRem);
			
		}
	xmMapper.deleteXMAttachment(map);
	return Utility.rtJson(Utility.RETURN_OK, "删除成功", null);
	}	
	public String deleteRecInvoice(Map<String,Object> map){
		Map<String,Object>mapRem=null;
		List<String> list = Arrays.asList(String.valueOf(map.get("ids")).split(","));
		for(int i=0;i<list.size();i++){
			mapRem=new HashMap<String,Object>();
			mapRem.put("id", list.get(i));
			xmFinanceMapper.deleteRecInvoice(mapRem);
			
		}
		xmMapper.deleteXMAttachment(map);
		return Utility.rtJson(Utility.RETURN_OK, "删除成功", null);
	}	
	public String listGdLoanByXmId(Map<String,Object> map){
		List<Map<String,Object>> list= xmFinanceMapper.listGdLoanByXmId(map);
		StringBuffer sb = new StringBuffer("");
		sb.append(Utility.lstMaptoJson(list));
		Utility.putSuccess(map);
		return sb.toString();
	}
	public String listPageXmReim(Map<String,Object> map){
		List<Map<String,Object>> list= xmFinanceMapper.listPageXmReim(map);
		StringBuffer sb = new StringBuffer("");
		sb.append(Utility.lstMaptoJson(list));
		Utility.putSuccess(map);
		return sb.toString();
	}
	public String getReimbursementById(Map<String,Object> map){
		Map<String,Object> mapRem= xmFinanceMapper.getReimbursementById(map);
		map.put("business_type", StaticData.XM_BZ);
		map.put("business_id", mapRem.get("id"));
		List<Map<String,String>> attList = xmMapper.getXMTempAttachmentByGDId(map);
		StringBuilder attachmentId = new StringBuilder("");
		StringBuilder attachmentName = new StringBuilder("");
		if(attList != null && attList.size() > 0){
			for(int i=0;i<attList.size();i++){
				Map<String,String> m = attList.get(i);
				if(m != null){
					if(i==0){
						attachmentId.append(m.get("attachmentId"));
						attachmentName.append(m.get("attachmentName"));
					}else{
						attachmentId.append(",").append(m.get("attachmentId"));
						attachmentName.append("*").append(m.get("attachmentName"));
					}
				}
			}
		}
		mapRem.put("attachmentId", attachmentId.toString());
		mapRem.put("attachmentName", attachmentName.toString());
		return Utility.toJson(mapRem);
	}
	public String addXMRecInvoice(Map<String,Object> map){
		String recInvoiceId=UUID.randomUUID().toString();
		map.put("id", recInvoiceId);   	
		map.put("status",StaticData.NEW_CREATE);
		map.put("business_id",recInvoiceId);
		map.put("business_type",StaticData.XM_SP);
		xmFinanceMapper.addXMRecInvoice(map); 
		List<String> atts = Arrays.asList(String.valueOf(map.get("attachmentId")).split(","));
	    //项目报账对借款单销账处理
		List<Map<String,Object>> attList = getAttList(map, atts);
		if(attList.size() > 0){
			xmMapper.addXMAttachment(attList);
		}  
		
		return Utility.rtJson(Utility.RETURN_OK, "添加成功", null);
	}
		public String updateXMRecInvoice(Map<String,Object> map){ 
			
			xmFinanceMapper.updateXMRecInvoice(map); 
			//删除相关从表
			map.put("business_id", map.get("id"));
			map.put("id", map.get("id"));
			map.put("business_type", StaticData.XM_SP);
			xmMapper.deleteXMAttachment(map);
			List<String> atts = Arrays.asList(String.valueOf(map.get("attachmentId")).split(","));
			List<Map<String,Object>> attList = getAttList(map, atts);
			if(attList.size() > 0){
				xmMapper.addXMAttachment(attList);
			}  
			
			return Utility.rtJson(Utility.RETURN_OK, "更新成功", null);
		}
		public String getXmRecInvoiceById(Map<String,Object> map){
			Map<String,Object>mapRecIn=xmFinanceMapper.getXmRecInvoiceById(map);
			//附件
			mapRecIn.put("business_id", map.get("id"));
			mapRecIn.put("business_type",StaticData.XM_SP);
			List<Map<String,String>> attList = xmMapper.getXMTempAttachmentByGDId(mapRecIn);
			StringBuilder attachmentId = new StringBuilder("");
			StringBuilder attachmentName = new StringBuilder("");
			StringBuilder gdIds = new StringBuilder("");
			StringBuilder gdNames = new StringBuilder("");
			if(attList != null && attList.size() > 0){
				for(int i=0;i<attList.size();i++){
					Map<String,String> m = attList.get(i);
					if(m != null){
						if(i==0){
							attachmentId.append(m.get("attachmentId"));
							attachmentName.append(m.get("attachmentName"));
						}else{
							attachmentId.append(",").append(m.get("attachmentId"));
							attachmentName.append("*").append(m.get("attachmentName"));
						}
					}
				}
			}
			mapRecIn.put("attachmentId", attachmentId.toString());
			mapRecIn.put("attachmentName", attachmentName.toString());
			
			return Utility.toJson(mapRecIn);
		}
	public String addXMReimbursement(Map<String,Object> map){
		String rem_id=UUID.randomUUID().toString();
		map.put("id", rem_id);   	
		map.put("status",StaticData.NEW_CREATE);
		map.put("business_id",rem_id);
		map.put("business_type",StaticData.XM_BZ);
		if("0".equals(String.valueOf(map.get("is_borrow")))){
			BigDecimal loan_money = new BigDecimal(String.valueOf(map.get("loan_money")));
			map.put("loan_money", loan_money);
		}
		xmFinanceMapper.addXMReimbursement(map); 
		
		
		List<String> atts = Arrays.asList(String.valueOf(map.get("attachmentId")).split(","));
		if("1".equals(String.valueOf(map.get("is_borrow")))){
			//项目报账对借款单销账处理
			String strs = String.valueOf(map.get("products"));
	    	List<Map<String,String>> gdSetList = getGdsetList(map, strs);
			if(gdSetList.size() > 0){
				xmFinanceMapper.addXmBzTmp(gdSetList);
			}
		}
		List<Map<String,Object>> attList = getAttListBz(map, atts);
		if(attList.size() > 0){
			xmMapper.addXMAttachment(attList);
		}  
		
		return Utility.rtJson(Utility.RETURN_OK, "添加成功", null);
	}
	private List<Map<String,String>> getGdsetList(Map<String,Object> map,String strs ){
		List<Map<String,String>> gdSetList=new ArrayList<Map<String,String>>();
		if(!Utility.isNullorEmpty(strs)){
			String[] strArr=strs.split(";");
			for(int i=0;i<strArr.length;i++){
				Map<String,String> m= Utility.json2Map(strArr[i]);
				m.put("rem_id", String.valueOf(map.get("id")));
				m.put("loan_id", String.valueOf(m.get("loan_id")));
				m.put("money", String.valueOf(m.get("money")));
				gdSetList.add(m);
			}
		}
		return gdSetList;
	}
	
	public String updateXMReimbursement(Map<String,Object> map){  	
		if("0".equals(String.valueOf(map.get("is_borrow")))){
			BigDecimal loan_money = new BigDecimal(String.valueOf(map.get("loan_money")));
			map.put("loan_money", loan_money);
		}
		xmFinanceMapper.updateXMReimbursement(map); 
		//删除相关从表
		map.put("business_id", map.get("id"));
		map.put("rem_id", map.get("id"));
		map.put("business_type", StaticData.XM_BZ);
		xmMapper.deleteXMAttachment(map);
		List<String> atts = Arrays.asList(String.valueOf(map.get("attachmentId")).split(","));
		List<Map<String,Object>> attList = getAttListBz(map, atts);
		if(attList.size() > 0){
			xmMapper.addXMAttachment(attList);
		}  
		if("1".equals(String.valueOf(map.get("is_borrow")))){
			//项目报账对借款单销账处理
			xmFinanceMapper.deleteTempXmBz(map);
			String strs = String.valueOf(map.get("products"));
	    	List<Map<String,String>> gdSetList = getGdsetList(map, strs);
			if(gdSetList.size() > 0){
				xmFinanceMapper.addXmBzTmp(gdSetList);
			}
		}
		return Utility.rtJson(Utility.RETURN_OK, "更新成功", null);
	}
	//项目借款销账
	public String updateXmRemLoan(Map<String,Object> map){  	
		
		List<String> list = Arrays.asList(String.valueOf(map.get("ids")).split(","));
		//确认实际放款
		//获取公司账套信息
		map.put("id", map.get("finance_company_id"));
	    Map<String,Object> cbMap=financeMapper.getFinanceCompanyById(map);
		BigDecimal cBMoney = new BigDecimal(String.valueOf(cbMap.get("money")));
		//公司账户减少金额subFinanceCompanyMoney
		map.put("bank_id", map.get("finance_company_id"));
		financeMapper.subFinanceCompanyMoney(map);
		Calendar now = Calendar.getInstance();
		for(int i=0;i<list.size();i++){
			Map<String,Object>mapRem=new HashMap<String,Object>();
			String []arrRem=String.valueOf(list.get(i)).split(";");
			mapRem.put("xm_id", arrRem[2]);
			mapRem.put("rem_id", arrRem[0]);
			mapRem.put("xbz_id", arrRem[4]);
			now.add(Calendar.SECOND, 1);
			String operation_date = new SimpleDateFormat(StaticData.OPERATION_DATE_FORMATTER).format(now.getTime());
			Map<String,Object> xmRemMap = xmFinanceMapper.getReimbursementById(mapRem);
			BigDecimal remMoney = new BigDecimal(String.valueOf(arrRem[1]));//报账金额
			BigDecimal sumRemMoney = new BigDecimal(String.valueOf(xmRemMap.get("reimbursement")));//报账金额

			if(remMoney.setScale(1,   BigDecimal.ROUND_HALF_UP).doubleValue()==sumRemMoney.setScale(1,   BigDecimal.ROUND_HALF_UP).doubleValue()){
				mapRem.put("yet", "1");
			}else{
				mapRem.put("yet", "0");
			}
			xmFinanceMapper.updateXmRem(mapRem);
			xmFinanceMapper.updateXmRemDetail(mapRem);
			Map<String,Object> cLogM = new HashMap<String,Object>();
			//公司账户减少金额，增加log 
			BigDecimal reimbursement = new BigDecimal(String.valueOf(xmRemMap.get("reimbursement")));
			cLogM.put("f_c_log_id", UUID.randomUUID().toString());
			String summary="";
			if("0".equals(String.valueOf(arrRem[3]))){
				cLogM.put("type",StaticData.FINANCE_OUT);
					summary= "项目【"+xmRemMap.get("xm_code")+"】项目报账支出【"+xmRemMap.get("reimbursement")+"】";
			}else{
				if("1".equals(String.valueOf(map.get("flagType")))){
					cLogM.put("type",StaticData.FINANCE_IN);
					summary= "项目【"+xmRemMap.get("xm_code")+"】项目工单报账收入【"+arrRem[1]+"】";
				}else{
					cLogM.put("type",StaticData.FINANCE_OUT);
					summary= "项目【"+xmRemMap.get("xm_code")+"】项目工单报账支出【"+arrRem[1]+"】";
				}
			}
			cLogM.put("summary", summary);
			cLogM.put("customer_id", "");
			cLogM.put("customer", "");
			cLogM.put("finance_company_id", cbMap.get("id"));
			cLogM.put("finance_company_name", cbMap.get("bank"));
			cLogM.put("before_money", cBMoney);
			if("1".equals(String.valueOf(arrRem[3]))){
				cLogM.put("money", arrRem[1]);
			}else{
				cLogM.put("money", xmRemMap.get("reimbursement"));
			}
			cLogM.put("person_id", map.get("creator_id"));
			cLogM.put("person", map.get("creator"));
			cLogM.put("operation_date", operation_date);
			financeMapper.addFinanceCompanyLog(cLogM);
			//部门账户减少金额subFinanceDeptMoney
			String deptId = xmRemMap.get("admin_dept_id").toString();
			Map<String,Object> dbMap = financeMapper.getFinanceDeptByDeptId(deptId);
			dbMap.put("finance_dept_id",dbMap.get("id"));
			BigDecimal dBMoney = new BigDecimal(String.valueOf(dbMap.get("money")));
			if("1".equals(String.valueOf(arrRem[3]))){
				dbMap.put("money", arrRem[1]);
			}else{
				dbMap.put("money", xmRemMap.get("reimbursement"));
			}
			if("1".equals(String.valueOf(map.get("flagType")))){
				
				financeMapper.addFinanceDeptMoneyByDept(dbMap);
			}else{
				
				financeMapper.subFinanceDeptMoney(dbMap);
			}
			//部门账户减少金额，增加log
			if("0".equals(String.valueOf(arrRem[3]))){
					dbMap.put("type",StaticData.FINANCE_OUT);
					summary= "项目【"+xmRemMap.get("xm_code")+"】项目报账支出【"+xmRemMap.get("reimbursement")+"】";
			}else{
				if("1".equals(String.valueOf(map.get("flagType")))){
					dbMap.put("type",StaticData.FINANCE_IN);
					summary= "项目【"+xmRemMap.get("xm_code")+"】项目工单报账收入【"+arrRem[1]+"】";
				}else{
					dbMap.put("type",StaticData.FINANCE_OUT);
					summary= "项目【"+xmRemMap.get("xm_code")+"】项目工单报账支出【"+arrRem[1]+"】";
				}
			}
			dbMap.put("summary", summary);
			if("1".equals(String.valueOf(arrRem[3]))){
				dbMap.put("proof_type", StaticData.Proof_REM_LOAN);	
			}else{
				dbMap.put("proof_type", StaticData.Proof_REM);	
				
			}
			dbMap.put("proof_id", xmRemMap.get("id"));
			dbMap.put("before_money", dBMoney);
			dbMap.put("person_id", map.get("creator_id"));
			dbMap.put("person", map.get("creator"));
			dbMap.put("operation_date", operation_date);
			financeMapper.addFinanceDeptLog(dbMap);
			if(!"1".equals(String.valueOf(arrRem[3]))){
				xmRemMap.put("bus_id", xmRemMap.get("id"));
				xmRemMap.put("financeCompanyLogId", cLogM.get("f_c_log_id"));
				//更新updateXMPay
				xmFinanceMapper.addFinLogIdXMPay(xmRemMap);
			}
			cBMoney=cBMoney.subtract(reimbursement);
			dBMoney=dBMoney.subtract(reimbursement);
		}
		return Utility.rtJson(Utility.RETURN_OK, "项目销账成功！", null);
	}
	private List<Map<String,Object>> getAttListBz(Map<String,Object> map,List<String> list){
		List<Map<String,Object>> attList=new ArrayList<Map<String,Object>>();
		for(int i=0;i<list.size();i++){
			if(!Utility.isNullorEmpty(list.get(i))){
				Map<String,Object> m= new HashMap<String,Object>();
				m.put("operation_date", new SimpleDateFormat(StaticData.OPERATION_DATE_FORMATTER).format(new Date()));
				m.put("user_id", map.get("att_user_id"));
				m.put("user_name", map.get("att_user_name"));
				m.put("xm_id", map.get("xm_id"));
				m.put("business_id", map.get("id"));
				m.put("attachment_id", list.get(i));
				m.put("business_type", StaticData.XM_BZ);
				attList.add(m);
			}
		}
		return attList;
	}
	private List<Map<String,Object>> getAttList(Map<String,Object> map,List<String> list){
		List<Map<String,Object>> attList=new ArrayList<Map<String,Object>>();
		for(int i=0;i<list.size();i++){
			if(!Utility.isNullorEmpty(list.get(i))){
				Map<String,Object> m= new HashMap<String,Object>();
				m.put("operation_date", new SimpleDateFormat(StaticData.OPERATION_DATE_FORMATTER).format(new Date()));
				m.put("user_id", map.get("att_user_id"));
				m.put("user_name", map.get("att_user_name"));
				m.put("xm_id", map.get("xm_id"));
				m.put("business_id", map.get("id"));
				m.put("attachment_id", list.get(i));
				m.put("business_type", StaticData.XM_SP);
				attList.add(m);
			}
		}
		return attList;
	}
	/**
	 * 财务放款
	 */
	public String updateXmFinanceOut(Map<String,Object> map){
		String xmPayIds=map.get("ids").toString();
		String[] idsArr=xmPayIds.split(",");
		//获取公司账套信息
		map.put("id", map.get("finance_company_id"));
		Map<String,Object> cbMap=financeMapper.getFinanceCompanyById(map);
		BigDecimal cBMoney = new BigDecimal(String.valueOf(cbMap.get("money")));
		//公司账户减少金额subFinanceCompanyMoney
		map.put("bank_id", map.get("finance_company_id"));
		financeMapper.subFinanceCompanyMoney(map);
		
		Calendar now = Calendar.getInstance();
//		BigDecimal advYetMoney = new BigDecimal(0);//还款总额
		BigDecimal compMoney = new BigDecimal(0);//比较金额
		for(int i=0;i<idsArr.length;i++){
			now.add(Calendar.SECOND, 1);
			String operation_date = new SimpleDateFormat(StaticData.OPERATION_DATE_FORMATTER).format(now.getTime());
			Map<String,Object>advMap=new HashMap<String,Object>();
			map.put("id", idsArr[i]);
			Map<String,Object> xmPayMap = xmFinanceMapper.viewXmPay(map);
			Map<String,Object> cLogM = new HashMap<String,Object>();
			advMap.put("id", xmPayMap.get("id"));
			advMap.put("xm_id", xmPayMap.get("xm_id"));
			advMap.put("worker_id", xmPayMap.get("pay_to_id"));
			//更新班组垫款本金，与已经还款金额
//			List<Map<String,Object>> listAdv = gdMapper.listGdYetAdvancesByYetId(advMap);
//			if(listAdv != null && listAdv.size()>0){
//				for(int j=0;j<listAdv.size();j++){
//					Map<String,Object> m =listAdv.get(j);
//					BigDecimal yet_money = new BigDecimal(String.valueOf(m.get("yet_money")));//本次还款金额
//					advYetMoney=advYetMoney.add(yet_money);
//					Map<String,Object>mapTab=new HashMap<String,Object>();
//					mapTab.put("voucher_id", idsArr[i]);
//					mapTab.put("yet", 3);
//					gdMapper.updateGdActualTaYetAdvances(mapTab);
//				}
//			}
			//公司账户减少金额，增加log 
			BigDecimal pay_value = new BigDecimal(String.valueOf(xmPayMap.get("pay_value")));
			pay_value=pay_value.subtract(new BigDecimal(String.valueOf(xmPayMap.get("cut_payment"))));
			
			cLogM.put("f_c_log_id", UUID.randomUUID().toString());
			cLogM.put("type",StaticData.FINANCE_OUT);
			String summary="";
			if(Integer.parseInt(xmPayMap.get("pay_type").toString())==2){
			 summary= "项目【"+xmPayMap.get("xm_code")+"】支付采购商"+xmPayMap.get("pay_to_name");
			}else if(Integer.parseInt(xmPayMap.get("pay_type").toString())==1){
				summary= "项目【"+xmPayMap.get("xm_code")+"】支付【"+xmPayMap.get("pay_to_name")+"】支付款("+String.valueOf(xmPayMap.get("pay_value"))+")减去扣垫款额("+String.valueOf(xmPayMap.get("cut_payment"))+")="+pay_value;
			}
			cLogM.put("summary", summary);
			cLogM.put("customer_id", xmPayMap.get("pay_to_id"));
			cLogM.put("customer", xmPayMap.get("pay_to_name"));
			cLogM.put("finance_company_id", cbMap.get("id"));
			cLogM.put("finance_company_name", cbMap.get("bank"));
			cLogM.put("before_money", cBMoney);
			cLogM.put("money", pay_value);
			cLogM.put("person_id", map.get("author_id"));
			cLogM.put("person", map.get("author_name"));
			cLogM.put("operation_date", operation_date);
			financeMapper.addFinanceCompanyLog(cLogM);
			//部门账户减少金额subFinanceDeptMoney
			
			String deptId = xmPayMap.get("dept_id").toString();
			Map<String,Object> dbMap = financeMapper.getFinanceDeptByDeptId(deptId);
			dbMap.put("finance_dept_id",dbMap.get("id"));
			BigDecimal dBMoney = new BigDecimal(String.valueOf(dbMap.get("money")));
			dbMap.put("money",  pay_value);
			if(pay_value.compareTo(compMoney)>0){
			financeMapper.subFinanceDeptMoney(dbMap);
			}
			//部门账户减少金额，增加log
			dbMap.put("type", StaticData.FINANCE_OUT);
			dbMap.put("summary", summary);
			if(Integer.parseInt(xmPayMap.get("pay_type").toString())==2){
			dbMap.put("proof_type", StaticData.Proof_XM_SUPPLY_PAY);
			}else if(Integer.parseInt(xmPayMap.get("pay_type").toString())==1){
				dbMap.put("proof_type", StaticData.Proof_XM_WORKER_PAY);	
			}
			dbMap.put("money",  pay_value);
			dbMap.put("proof_id", xmPayMap.get("id"));
			dbMap.put("before_money", dBMoney);
			dbMap.put("person_id", map.get("author_id"));
			dbMap.put("person", map.get("author_name"));
			dbMap.put("operation_date", operation_date);
			financeMapper.addFinanceDeptLog(dbMap);
			
			
			xmPayMap.put("bus_id", xmPayMap.get("id"));
			xmPayMap.put("financeCompanyLogId", cLogM.get("f_c_log_id"));
				
		//更新supplier_finance_out_log
//			if(Integer.parseInt(xmPayMap.get("pay_type").toString())==2){
//			xmFinanceMapper.addFinLogIdSupFinanceLog(xmPayMap);
//			}else if(Integer.parseInt(xmPayMap.get("pay_type").toString())==1){
//				xmFinanceMapper.addFinLogIdWorkerFinanceLog(xmPayMap);	
//			}
			//更新updateXMPay
//			List<Map<String,Object>> listWork= xmFinanceMapper.viewXmPayDetail(map);
//			if(listWork!=null&&listWork.size()>0){
//				for(int k=0;k<listWork.size();k++){
//					Map<String,Object> mapWork =new HashMap<String,Object>();
//					mapWork.put("worker_id",xmPayMap.get("pay_to_id"));
//					mapWork.put("gd_id",listWork.get(k).get("gd_id"));
//					mapWork.put("now_pay", listWork.get(k).get("now_pay"));
//					xmFinanceMapper.updateXMWorkerFin(mapWork);
//				}
//			}
			xmFinanceMapper.addFinLogIdXMPay(xmPayMap);
			cBMoney=cBMoney.subtract(pay_value);
			dBMoney=dBMoney.subtract(pay_value);
		}
		return Utility.rtJson(Utility.RETURN_OK, "添加成功", null);
	}
	
	/**
	 * 放款给供应商
	 */
	public String updateXmSupFinanceOut(Map<String,Object> map){
		String xmPayIds=map.get("ids").toString();
		String[] idsArr=xmPayIds.split(",");
		//获取公司账套信息
		map.put("id", map.get("finance_company_id"));
		Map cbMap=financeMapper.getFinanceCompanyById(map);
		Double cBMoney=Double.valueOf(cbMap.get("money").toString());
		//公司账户减少金额subFinanceCompanyMoney
		map.put("bank_id", map.get("finance_company_id"));
		financeMapper.subFinanceCompanyMoney(map);
		
		for(int i=0;i<idsArr.length;i++){
			map.put("id", idsArr[i]);
			Map xmPayMap=xmFinanceMapper.viewXmPay(map);
			Map cLogM=new HashMap();
		//公司账户减少金额，增加log 
			Double pay_value=Double.valueOf(xmPayMap.get("pay_value").toString());
			cLogM.put("f_c_log_id", UUID.randomUUID().toString());
			cLogM.put("type",StaticData.FINANCE_OUT);
			String summary="";
			if(Integer.parseInt(xmPayMap.get("pay_type").toString())==2){
			 summary= "项目【"+xmPayMap.get("xm_code")+"】支付采购商"+xmPayMap.get("pay_to_name");
			}else if(Integer.parseInt(xmPayMap.get("pay_type").toString())==1){
				summary= "项目【"+xmPayMap.get("xm_code")+"】支付施工方"+xmPayMap.get("pay_to_name");
			}
			cLogM.put("summary", summary);
			cLogM.put("customer_id", xmPayMap.get("pay_to_id"));
			cLogM.put("customer", xmPayMap.get("pay_to_name"));
			cLogM.put("finance_company_id", cbMap.get("id"));
			cLogM.put("finance_company_name", cbMap.get("bank"));
			cLogM.put("before_money", cBMoney);
		
			cLogM.put("money", xmPayMap.get("pay_value"));
			cLogM.put("person_id", map.get("author_id"));
			cLogM.put("person", map.get("author_name"));
			cLogM.put("operation_date",  new SimpleDateFormat(StaticData.OPERATION_DATE_FORMATTER).format(new Date()));
			financeMapper.addFinanceCompanyLog(cLogM);
		//部门账户减少金额subFinanceDeptMoney
			
			String deptId=xmPayMap.get("dept_id").toString();
	
			Map dbMap =financeMapper.getFinanceDeptByDeptId(deptId);
			dbMap.put("finance_dept_id",dbMap.get("id"));
	
			Double dBMoney=Double.valueOf(dbMap.get("money").toString());
			dbMap.put("money", xmPayMap.get("pay_value"));
			financeMapper.subFinanceDeptMoney(dbMap);
		//部门账户减少金额，增加log
			dbMap.put("type", StaticData.FINANCE_OUT);
			dbMap.put("summary", summary);
			dbMap.put("proof_type", StaticData.Proof_XM_SUPPLY_PAY);
			dbMap.put("proof_id", xmPayMap.get("id"));
			dbMap.put("before_money", dBMoney);
			dbMap.put("person_id", map.get("author_id"));
			dbMap.put("person", map.get("author_name"));
			dbMap.put("operation_date",  new SimpleDateFormat(StaticData.OPERATION_DATE_FORMATTER).format(new Date()));
			financeMapper.addFinanceDeptLog(dbMap);
			
			xmPayMap.put("bus_id", xmPayMap.get("id"));
			xmPayMap.put("financeCompanyLogId", cLogM.get("f_c_log_id"));
		//更新supplier_finance_out_log
//			if(Integer.parseInt(xmPayMap.get("pay_type").toString())==2){
//			xmFinanceMapper.addFinLogIdSupFinanceLog(xmPayMap);
//			}
		//更新updateXMPay
			xmFinanceMapper.addFinLogIdXMPay(xmPayMap);
			cBMoney=cBMoney-pay_value;
			dBMoney=dBMoney-pay_value;
		}
		return Utility.rtJson(Utility.RETURN_OK, "添加成功", null);
	}
	/**
	 * 放款给施工队
	 */
	public String updateXmWorkerOut(Map<String,Object> map){
		String xmPayIds=map.get("ids").toString();
		String[] idsArr=xmPayIds.split(",");
		//获取公司账套信息
		map.put("id", map.get("finance_company_id"));
		Map<String,Object> cbMap=financeMapper.getFinanceCompanyById(map);
		Double cBMoney=Double.valueOf(cbMap.get("money").toString());
		//公司账户减少金额subFinanceCompanyMoney
		map.put("bank_id", map.get("finance_company_id"));
		financeMapper.subFinanceCompanyMoney(map);
		
		for(int i=0;i<idsArr.length;i++){
			map.put("id", idsArr[i]);
			Map<String,Object> xmPayMap=xmFinanceMapper.viewXmPay(map);
			Map<String,Object> cLogM=new HashMap<String,Object>();
		//公司账户减少金额，增加log 
			Double pay_value=Double.valueOf(xmPayMap.get("pay_value").toString());
			cLogM.put("f_c_log_id", UUID.randomUUID().toString());
			cLogM.put("type", StaticData.FINANCE_OUT);
			String summary= "项目【"+xmPayMap.get("xm_code")+"】支付施工款"+xmPayMap.get("pay_to_name");
			cLogM.put("summary", summary);
			cLogM.put("customer_id", xmPayMap.get("pay_to_id"));
			cLogM.put("customer", xmPayMap.get("pay_to_name"));
			cLogM.put("finance_company_id", cbMap.get("id"));
			cLogM.put("finance_company_name", cbMap.get("bank"));
			cLogM.put("before_money", cBMoney);
		
			cLogM.put("money", xmPayMap.get("pay_value"));
			cLogM.put("person_id", map.get("author_id"));
			cLogM.put("person", map.get("author_name"));
			cLogM.put("operation_date",  new SimpleDateFormat(StaticData.OPERATION_DATE_FORMATTER).format(new Date()));
			financeMapper.addFinanceCompanyLog(cLogM);
		//部门账户减少金额subFinanceDeptMoney
			
			String deptId=xmPayMap.get("dept_id").toString();
	
			Map<String,Object> dbMap =financeMapper.getFinanceDeptByDeptId(deptId);
			dbMap.put("finance_dept_id",dbMap.get("id"));
			dbMap.put("money", xmPayMap.get("pay_value"));
			Double dBMoney=Double.valueOf(dbMap.get("money").toString());
			financeMapper.subFinanceDeptMoney(dbMap);
		//部门账户减少金额，增加log
			dbMap.put("type", StaticData.FINANCE_OUT);
			dbMap.put("summary", summary);
			dbMap.put("proof_type", StaticData.Proof_XM_WORKER_PAY);
			dbMap.put("proof_id", xmPayMap.get("id"));
			dbMap.put("before_money", dBMoney);
			dbMap.put("person_id", map.get("author_id"));
			dbMap.put("person", map.get("author_name"));
			dbMap.put("operation_date",  new SimpleDateFormat(StaticData.OPERATION_DATE_FORMATTER).format(new Date()));
			financeMapper.addFinanceDeptLog(dbMap);
			
			xmPayMap.put("bus_id", xmPayMap.get("id"));
			xmPayMap.put("financeCompanyLogId", cLogM.get("f_c_log_id"));
		//更新gd_worker_finance_out_log
//			xmFinanceMapper.addFinLogIdWorkerFinanceLog(xmPayMap);
		//更新updateXMPay
			xmFinanceMapper.addFinLogIdXMPay(xmPayMap);
			cBMoney=cBMoney-pay_value;
			dBMoney=dBMoney-pay_value;
		}
		return Utility.rtJson(Utility.RETURN_OK, "添加成功", null);
	}
	//财务未处理项目收款管理
	public String listPageXMFinanceEarn(Map<String,Object> map){
		List<Map<String,Object>> list= xmFinanceMapper.listPageXMFinanceEarn(map);
		StringBuffer sb = new StringBuffer("");
		sb.append(Utility.lstMaptoJson(list));
		Utility.putSuccess(map);
		return sb.toString();
	}
	//财务已处理项目收款管理
	public String listPageXMFinanceFinishEarn(Map<String,Object> map){
		List<Map<String,Object>> list= xmFinanceMapper.listPageXMFinanceFinishEarn(map);
		StringBuffer sb = new StringBuffer("");
		sb.append(Utility.lstMaptoJson(list));
		Utility.putSuccess(map);
		return sb.toString();
	}
	
	/**
	 * 项目收款
	 */
	public String updateXmEarn(Map<String,Object> map){
		String xmPayIds=map.get("ids").toString();
		String[] idsArr=xmPayIds.split(",");
		//获取公司账套信息
		map.put("id", map.get("finance_company_id"));
		Map<String,Object> cbMap = financeMapper.getFinanceCompanyById(map);
		BigDecimal cBMoney = new BigDecimal(String.valueOf(cbMap.get("money")));
		//公司账户增加金额addFinanceCompanyMoney
		map.put("bank_id", map.get("finance_company_id"));
		financeMapper.addFinanceCompanyMoney(map);
		Calendar now = Calendar.getInstance();
		for(int i=0;i<idsArr.length;i++){
			now.add(Calendar.SECOND, 1);
			String operation_date = new SimpleDateFormat(StaticData.OPERATION_DATE_FORMATTER).format(now.getTime());
			map.put("id", idsArr[i]);
			Map<String,Object> xmInMap = xmFinanceMapper.getInMoneyById(map);
			BigDecimal in_money = new BigDecimal(String.valueOf(xmInMap.get("in_money")));//该项目回款金额
			BigDecimal manage_money = new BigDecimal(String.valueOf(xmInMap.get("manage_money")));//管理费
			in_money = in_money.subtract(manage_money);
			Map<String,Object> cLogM = new HashMap<String,Object>();
			//公司账户增加金额，增加log 
			cLogM.put("f_c_log_id", UUID.randomUUID().toString());
			cLogM.put("type", StaticData.FINANCE_IN);
			String summary = "项目【"+xmInMap.get("xm_code")+"】收款【"+in_money+"】";
			cLogM.put("summary", summary);
			cLogM.put("customer_id", xmInMap.get("customer_id"));
			cLogM.put("customer", xmInMap.get("customer"));
			cLogM.put("finance_company_id", cbMap.get("id"));
			cLogM.put("finance_company_name", cbMap.get("bank"));
			cLogM.put("before_money", cBMoney);
			cLogM.put("money", in_money);
			cLogM.put("person_id", map.get("author_id"));
			cLogM.put("person", map.get("author_name"));
			cLogM.put("operation_date",  operation_date);
			financeMapper.addFinanceCompanyLog(cLogM);
			
		//部门账户增加金额addFinanceDeptMoney
			String deptId = xmInMap.get("dept_id").toString();
			Map<String,Object> dbMap = financeMapper.getFinanceDeptByDeptId(deptId);
			BigDecimal dBMoney = new BigDecimal(String.valueOf(dbMap.get("money")));
			dbMap.put("finance_dept_id",dbMap.get("id"));
			dbMap.put("money", in_money);
			financeMapper.addFinanceDeptMoney(dbMap);
			
		//部门账户增加金额，增加log
			dbMap.put("type", StaticData.FINANCE_IN);
			dbMap.put("summary", summary);
			dbMap.put("proof_type", StaticData.Proof_XM_EARN);
			dbMap.put("proof_id", xmInMap.get("id"));
			dbMap.put("before_money", dBMoney);
			dbMap.put("person_id", map.get("author_id"));
			dbMap.put("person", map.get("author_name"));
			dbMap.put("operation_date",  operation_date);
			financeMapper.addFinanceDeptLog(dbMap);
			
			//更新updateXMInmoney
			xmInMap.put("bus_id", xmInMap.get("id"));
			xmInMap.put("financeCompanyLogId", cLogM.get("f_c_log_id"));
			xmFinanceMapper.addFinLogIdXMInMoney(xmInMap);
			
			cBMoney = cBMoney.add(in_money);
			dBMoney = dBMoney.add(in_money);
		}
		return Utility.rtJson(Utility.RETURN_OK, "添加成功", null);
	}
	
	 /**
     * 项目结算收入开票记录列表
     */
	public String listXMInvoiceByXMId(Map<String,Object> map){
		List<Map<String,Object>> list= xmFinanceMapper.listXMInvoiceByXMId(map);
		StringBuffer sb = new StringBuffer("");
		sb.append(Utility.lstMaptoJson(list));
		Utility.putSuccess(map);
		return sb.toString();
	}
	 /**
     * 项目结算收入开票记录列表
     */
	public String listXMEndInMoneyDetail(Map<String,Object> map){
		List<Map<String,Object>> list= xmFinanceMapper.listXMEndInMoneyDetail(map);
		StringBuffer sb = new StringBuffer("");
		sb.append(Utility.lstMaptoJson(list));
		Utility.putSuccess(map);
		return sb.toString();
	}

	
	/**
	 * 结算项目收入
	 * @param map
	 * @return
	 */
	public String hasXMEndInMoney(Map<String,Object> map){
		return String.valueOf(xmFinanceMapper.hasXMEndInMoney(map));
	}
	
	 /**
     * 项目结算采购商结算
     */
	public String getXMPurchaseBalanceByXMId(Map<String,Object> map){
		List<Map<String,Object>> list= xmFinanceMapper.getXMPurchaseBalanceByXMId(map);
		StringBuffer sb = new StringBuffer("");
		sb.append(Utility.lstMaptoJson(list));
		Utility.putSuccess(map);
		return sb.toString();
	}	
	 /**
     * 项目结算分包商结算
     */
	public String listXMWorkersBalanceByXMId(Map<String,Object> map){
		List<Map<String,Object>> list= xmFinanceMapper.listXMWorkersBalanceByXMId(map);
		StringBuffer sb = new StringBuffer("");
		sb.append(Utility.lstMaptoJson(list));
		Utility.putSuccess(map);
		return sb.toString();
	}	
	/**
	 * 结算项目支出
	 * @param map
	 * @return
	 */
	public String hasXMEndPayMain(Map<String,Object> map){
		return String.valueOf(xmFinanceMapper.hasXMEndPayMain(map));
	}
	
	
	 /**
     * 项目结算支出审批列表
     */
	public String listXMEndPayMain(Map<String,Object> map){
		List<Map<String,Object>> list=null;
		if(map.get("pay_type").toString().equals("1")){
			  list= xmFinanceMapper.listXmEndFbPayment(map);
		}
		else
		{
			  list= xmFinanceMapper.listXmEndCgPayment(map);	
		}
		StringBuffer sb = new StringBuffer("");
		sb.append(Utility.lstMaptoJson(list));
		Utility.putSuccess(map);
		return sb.toString();
	}
	 /**
     * 项目结算支付供应商列表
     */
	public String listFBEndPayByXMIdAndWorkerId(Map<String,Object> map){
		List<Map<String,Object>> list=null;
 		list= xmFinanceMapper.listFBEndPayByXMIdAndWorkerId(map); 
		StringBuffer sb = new StringBuffer("");
		sb.append(Utility.lstMaptoJson(list));
		Utility.putSuccess(map);
		return sb.toString();
	}
	
	 /**
     * 项目结算支付采购商列表
     */
	public String listCGEndPayByXMIdAndsupplierId(Map<String,Object> map){
		List<Map<String,Object>> list=null;
 		list= xmFinanceMapper.listCGEndPayByXMIdAndsupplierId(map); 
		StringBuffer sb = new StringBuffer("");
		sb.append(Utility.lstMaptoJson(list));
		Utility.putSuccess(map);
		return sb.toString();
	}
	 /**
     * 项目结算支出审批
     */
	public String getXmEndPayMain(Map<String,Object> map){
	  Map<String,Object> mapReturn= xmFinanceMapper.getXmEndPayMain(map);
	  return Utility.toJson(mapReturn);
	}
	 /**
     * 项目结算支出审批列表添加
     */
	public String addXMEndPayMain(Map<String,Object> map){
		if(map.get("pay_type").equals("1")){
		Map<String,Object> m1=new HashMap();
		m1.put("id", UUID.randomUUID().toString());
		m1.put("xm_id", map.get("xm_id"));
		m1.put("xm_code", map.get("xm_code"));
		m1.put("xm_name", map.get("xm_name"));
		m1.put("customer", map.get("customer"));
		m1.put("pay_total", map.get("pay_total"));
		m1.put("remark", map.get("remark"));
		m1.put("pay_type", 1);
		xmFinanceMapper.addXMEndPayMain(m1);
		String gds=map.get("gds").toString();
		String[] gdsArr=gds.split(";");
    	for(int i=0;i<gdsArr.length;i++){
    		Map<String,String> gdMap= Utility.json2Map(gdsArr[i]);
    		Map<String,Object> m= new HashMap<String,Object>();
    		m.put("id", UUID.randomUUID().toString());
    		m.put("gd_id", gdMap.get("gd_id"));
    		m.put("gd_name", gdMap.get("gd_name"));
    		m.put("gd_code", gdMap.get("gd_code"));
    		m.put("xm_id", map.get("xm_id"));
    		m.put("gd_worker_id", gdMap.get("gd_worker_id"));
    		m.put("gd_worker_name", gdMap.get("gd_worker_name"));
    		m.put("actual_pay_total", gdMap.get("actual_pay_total"));
    		m.put("worker_pay", gdMap.get("worker_pay"));
    		m.put("already_pay", gdMap.get("already_pay"));
    		m.put("borrow_pay", gdMap.get("borrow_pay"));
    		m.put("interest", gdMap.get("interest"));
    		m.put("end_pay", gdMap.get("end_pay"));
    		m.put("cut_payment", gdMap.get("cut_payment"));
    		m.put("pay_total", gdMap.get("pay_total"));
    		m.put("remark", gdMap.get("remark"));
    		m.put("bus_id", gdMap.get("bus_id"));
    		m.put("creator", map.get("author_name"));
    		m.put("creator_id", map.get("author_id"));
    	   	xmFinanceMapper.addXmEndFbPayment(m);
    	}
		}else if(map.get("pay_type").equals("2")){
			Map<String,Object> m1=new HashMap();
			m1.put("id", UUID.randomUUID().toString());
			m1.put("xm_id", map.get("xm_id"));
			m1.put("xm_code", map.get("xm_code"));
			m1.put("xm_name", map.get("xm_name"));
			m1.put("customer", map.get("customer"));
			m1.put("pay_total", map.get("pay_total"));
			m1.put("remark", map.get("remark"));
			m1.put("pay_type", 2);
			xmFinanceMapper.addXMEndPayMain(m1);
			String gds=map.get("gds").toString();
			String[] gdsArr=gds.split(";");
	    	for(int i=0;i<gdsArr.length;i++){
	    		Map<String,String> gdMap= Utility.json2Map(gdsArr[i]);
	    		Map<String,Object> m= new HashMap<String,Object>();

	    		m.put("id", UUID.randomUUID().toString());
	    		m.put("gd_id", gdMap.get("gd_id"));
	    		m.put("gd_name", gdMap.get("gd_name"));
	    		m.put("gd_code", gdMap.get("gd_code"));
	    		m.put("xm_id", map.get("xm_id"));
	    		m.put("supplier_id", gdMap.get("supplier_id"));
	    		m.put("company", gdMap.get("company"));
	    		m.put("finance_out", gdMap.get("finance_out"));
	    		m.put("already_pay", gdMap.get("already_pay"));
	    		m.put("end_pay", gdMap.get("end_pay"));
	    		m.put("pay_total", gdMap.get("pay_total"));
	    		m.put("remark", gdMap.get("remark"));
	    		m.put("bus_id", gdMap.get("bus_id"));
	    		m.put("creator", map.get("author_name"));
	    		m.put("creator_id", map.get("author_id"));
	    	   	xmFinanceMapper.addXmEndCgPayment(m);
		}
		}
		return Utility.rtJson(Utility.RETURN_OK, "添加成功", null);	
	}
	 /**
     * 项目结算支出审批列表更新
     */
	public String updateXMEndPayMain(Map<String,Object> map){
		this.deleteXMEndPayMain(map);
		this.addXMEndPayMain(map);
		return Utility.rtJson(Utility.RETURN_OK, "更新成功", null);	
	}
	/**
     * 项目结算支出审批列表更新
     */
	public String deleteXMEndPayMain(Map<String,Object> map){
		xmFinanceMapper.deleteXmEndPayMain(map);
		if(map.get("pay_type").equals("2")){
		xmFinanceMapper.deleteXmEndCgPayment(map);
		}else if(map.get("pay_type").equals("1")){
		xmFinanceMapper.deleteXmEndFbPayment(map);
		}
		return Utility.rtJson(Utility.RETURN_OK, "删除成功", null);	
	}
	public String listPageXMWarranty(Map<String,Object> map){
		List<Map<String,Object>> list= xmFinanceMapper.listPageXMWarranty(map);
		StringBuffer sb = new StringBuffer("");
		sb.append(Utility.lstMaptoJson(list));
		Utility.putSuccess(map);
		return sb.toString();
	}
	 /**
     * 项目票号更新
     */
	public String updateInvoiceCode(Map<String,Object> map){
		xmFinanceMapper.updateInvoiceCode(map);
		return Utility.rtJson(Utility.RETURN_OK, "编辑成功", null);	
	}
}
